package com.maila.xiaoaoschool.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.activity.AddaddressActivity;
import com.maila.xiaoaoschool.util.StartActivityUtils;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.utils.AutoUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/31.
 */

public class AddressAdapter extends BaseAdapter {
    Context context;


    public AddressAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return 6;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_address, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if(i==0){
            holder.ivDefault.setVisibility(View.VISIBLE);
        }else {
            holder.ivDefault.setVisibility(View.GONE);
        }
        if (i == 5) {
            holder.rlLayout.setBackgroundColor(Color.parseColor("#f2f2f2"));
            holder.ivCantGo.setVisibility(View.VISIBLE);
            holder.tvAddress.setTextColor(Color.parseColor("#aaaaaa"));
            holder.tvName.setTextColor(Color.parseColor("#aaaaaa"));
        } else {
            holder.rlLayout.setBackgroundColor(Color.parseColor("#ffffff"));
            holder.ivCantGo.setVisibility(View.GONE);
            holder.tvAddress.setTextColor(Color.parseColor("#333333"));
            holder.tvName.setTextColor(Color.parseColor("#333333"));
        }
        holder.btnEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StartActivityUtils.start(context, AddaddressActivity.class);
            }
        });
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.rl_layout)
        AutoRelativeLayout rlLayout;
        @BindView(R.id.tv_address)
        TextView tvAddress;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.btn_edit)
        ImageView btnEdit;
        @BindView(R.id.iv_default)
        ImageView ivDefault;
        @BindView(R.id.iv_cant_go)
        ImageView ivCantGo;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
